from vec import Vec2
import math
import time
WIDTH = 500
HEIGHT = 500

pc = (0, 200, 0)
bc = (0, 0, 0)

lt = time.time()
dt = 0

pt_mid = Vec2(WIDTH / 2, HEIGHT / 2)
n_from = 50
n_to = 100
len = n_from
p = 0
p_spd = 1

def GetPtByLen(pt_mid, n):
    y_offset = n / math.sqrt(3) 
    pt_a = Vec2(pt_mid.x, pt_mid.y - y_offset)
    pt_d = Vec2(pt_mid.x, pt_mid.y + len / 2 / math.sqrt(3))
    pt_b = Vec2(pt_d.x - len / 2, pt_d.y)
    pt_c = Vec2(pt_d.x + len / 2, pt_d.y)

    return pt_a, pt_b, pt_c

def update():
    global dt, lt, len, p, p_spd
    ct = time.time()
    dt = ct - lt
    lt = ct

    p += p_spd * dt
    if p > 1.0:
        p = 1.0
        p_spd *= -1
    elif p < 0.0:
        p = 0.0
        p_spd *= -1

    len = n_from * (1 - p) + n_to * p

def draw():
    screen.fill(bc)
    a, b, c = GetPtByLen(pt_mid, len)
    screen.draw.line(a.raw_get(), b.raw_get(), pc)
    screen.draw.line(b.raw_get(), c.raw_get(), pc)
    screen.draw.line(c.raw_get(), a.raw_get(), pc)